package com.yangyouqi.posthorse.web.controller;

import com.yangyouqi.posthorse.core.domain.Customer;
import com.yangyouqi.posthorse.core.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

import static com.yangyouqi.posthorse.web.controller.OrderController.getsession;

/**
 * @author 杨友奇
 * @Time 2018/7/2
 * 用户查询个人信息
 */
@Controller
@RequestMapping("client")
public class ClientController {

    @Autowired
    private CustomerService customerService;

    /**
     * 进入个人信息页面
     * @return
     */
    @GetMapping("/info")
    public String info(HttpSession session, Model model){
        getsession(session,model,"customer");
        return "client/info";
    }

    /**
     * 进入关于我们信息页面
     * @return
     */
    @GetMapping("/aboutUs")
    public String aboutUs(HttpSession session, Model model){
        getsession(session,model,"customer");

        return "client/aboutUs";
    }

    /**
     * 进入申请页面
     * @return
     */
    @GetMapping("apply")
    public String apply(HttpSession session, Model model){

        Customer result = (Customer) session.getAttribute("customer");

        Customer customer = customerService.applyToDistributor(result.getId());
        model.addAttribute("customer",customer);
        return "client/info";
    }
}
